package com.exp.sys.entity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.exp.base.entity.BaseEntity;

@Entity
@Table(name="sys_department")
public class Department  extends BaseEntity{
    @NotBlank
    private String name="";
    
    private String parentId="";
    /**
     * ID全路径
     */
    @Column(length=2048)
    private String fullId="";
    
	public String getName() {
    	this.getClass().getName();
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	
	public String getFullId() {
		return fullId;
	}
	public void setFullId(String fullId) {
		this.fullId = fullId;
	}
	@Transient
	public void setParentIdList(List<String> parentIdList){
		parentIdList.remove("");
		if(CollectionUtils.isNotEmpty(parentIdList)){
			String parentIds = StringUtils.join(parentIdList,".");
			String fullId = parentIds + "."+getId();
			setFullId(fullId);
		}
	}
	
	@Transient
	public ArrayList<String> getParentIdList(){
		ArrayList<String> list = new ArrayList<String>();
		if(StringUtils.isNotEmpty(fullId)){
			list.addAll(Arrays.asList(fullId.split(".")));
		}
		list.remove("");
		list.remove(getId());
		return list;
	}

	@Transient
	public String getParentIds(){
		ArrayList<String> list = getParentIdList();
		return StringUtils.defaultIfBlank(StringUtils.join(list,"."),"");
	}

}
